<?php

//------------------------------------------------------------------
// File: eventDetail.code.php
// Author: Bryan Frost
// Date Created: 2010-03-25
//
// eventDetail.php codebehind
//------------------------------------------------------------------

require_once('dataAccess.php');
require_once('../lib/utility.php');
require_once('../classes/Player.class.php');
require_once('../classes/Event.class.php');
require_once('../classes/Team.class.php');


$eventId = $_GET['event'];
$tournamentId = $_GET['tournament'];


//if (is_numeric($eventId))
//{
//	$event = Event::GetEventData($eventId);
//	
//	$tournamentDate = $event->GetTournamentDate();
//	$tournamentFormat = $event->GetEventFormat();
//	$numberOfTeams = $event->GetNumberOfTeams();
//	
//	$teamsCollection = $event->GetTeamsCollection();
//}
//else
//{
//	// Invalid Event
//	// TODO: Provide invalid indicator.
//}

function GenerateEventTableRows()
{
	$teamsCollection = $GLOBALS["teamsCollection"];
	
	$i = 0;
	foreach ($teamsCollection as $key => $value)
	{
		$teamId = $teamsCollection[$key]->GetTeamId();
		$teamResult = ConvertIntegerToOrdinal($teamsCollection[$key]->GetConditionalResult());
		
		// Alternate rows use css class "alternate"
		$cssRow = ($i & 1 ? "class=alternate" : "");
		
		echo "<tr $cssRow><td>$teamId</td>";
		
		$numberOfTeamates = 0;

		$playerCollection = $teamsCollection[$key]->GetPlayerCollection();

		foreach($playerCollection as $key2 => $value)
		{
			$playerId = $playerCollection[$key2]->GetPlayerId();
			$firstName = $playerCollection[$key2]->GetFirstName();
			$lastName = $playerCollection[$key2]->GetLastName();

			$numberOfTeamates++;
			if ($numberOfTeamates <= 2 )
			{ 
				echo "<td><a href=playerDetail.php?player=$playerId>$firstName $lastName</a></td>";
			}
			else
			{
				// TODO: Add logic once AVA starts tracking more than 2 person teams.
				// (for now, only display first 2 teamates)
			}
		}
		
		echo "<td>$teamResult</td></tr>";
		
		$i++;
	}
}
	
?>